package com.hongdee.crm.statistics.controller;

import com.hongdee.base.entity.ResultEntity;
import com.hongdee.crm.statistics.service.ITCrmLossStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 名  称:
 * 类  型: class
 * 描  述: 流失统计
 * 路  径: com.hongdee.crm.statistics.controller
 * 作  者: 王帅
 * 日  期:
 */
@RestController
@RequestMapping("/crm/statistics/loss")
public class TCrmLossStatisticsController {


    @Autowired
    private ITCrmLossStatisticsService lossStatisticsService;

    /**
     * 流失客户未进店原因分析
     * @param uid
     * @param token
     * @param time
     * @return
     * @throws Exception
     */
    @RequestMapping("/notInStore")
    @ResponseBody
    public Map notInStore(@RequestParam(name = "uid", defaultValue = "") String uid,
                          @RequestParam(name = "token", defaultValue = "") String token,
                          @RequestParam(name = "time", defaultValue = "") String time,
                          @RequestParam(name = "companyId", defaultValue = "") String companyId,
                          @RequestParam(name = "area", defaultValue = "") String area,
                          @RequestParam(name = "brand", defaultValue = "") String brand) throws Exception {
        Map map = new HashMap();
        List<Map<String,Object>> list=lossStatisticsService.lossCustomerNotInStoreStatistics(uid,time,companyId,area,brand);
        map.put("success","true");
        map.put("dataList",list);
        map.put("msg","查询成功");
        return map;
    }

    /**
     * 在外保养原因统计分析
     * @param uid
     * @param token
     * @param time
     * @return
     * @throws Exception
     */
    @RequestMapping("/outsideMaintenance")
    @ResponseBody
    public ResultEntity outsideMaintenance(@RequestParam(name = "uid", defaultValue = "") String uid,
                                           @RequestParam(name = "token", defaultValue = "") String token,
                                           @RequestParam(name = "time", defaultValue = "") String time,
                                           @RequestParam(name = "companyId", defaultValue = "") String companyId,
                                           @RequestParam(name = "area", defaultValue = "") String area,
                                           @RequestParam(name = "brand", defaultValue = "") String brand) throws Exception {
        ResultEntity res=new ResultEntity();
        List<Map<String,Object>> list=lossStatisticsService.lossCustomerOutsideMaintenStatistics(uid,time,companyId,area,brand);
        res.setSuccess(true);
        res.setMsg("查询成功");
        res.setData(list);
        return res;
    }

    /**
     * 在外保养原因统计分析
     * @param uid
     * @param token
     * @param time
     * @return
     * @throws Exception
     */
    @RequestMapping("/lossPlace")
    @ResponseBody
    public ResultEntity lossPlace(@RequestParam(name = "uid", defaultValue = "") String uid,
                                           @RequestParam(name = "token", defaultValue = "") String token,
                                           @RequestParam(name = "time", defaultValue = "") String time,
                                           @RequestParam(name = "companyId", defaultValue = "") String companyId,
                                           @RequestParam(name = "area", defaultValue = "") String area,
                                           @RequestParam(name = "brand", defaultValue = "") String brand) throws Exception {
        ResultEntity res=new ResultEntity();
        List<Map<String,Object>> list=lossStatisticsService.lossPlace(uid,time,companyId,area,brand);
        res.setSuccess(true);
        res.setMsg("查询成功");
        res.setData(list);
        return res;
    }
}
